Hook up the shortname synthesizer to everything else. No more GC1234 names!
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 30 Aug 2002 14:50:03 +0000 (14:50 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 30 Aug 2002 14:50:03 +0000 (14:50 +0000)
gpsbabel/ChangeLog
gpsbabel/Makefile
gpsbabel/README
gpsbabel/defs.h
gpsbabel/gpsutil.c
gpsbabel/magproto.c
gpsbabel/main.c
gpsbabel/mkshort.c
gpsbabel/pcx.c
gpsbabel/waypt.c

index ff0fd40fcf7739309fbdfdc55a0c27acf6f885ac..4df26334bb4c20c72f13353c001e1afc41afdce3 100644 (file)
@@ -1,5 +1,7 @@
-NEW: blah blah
 NEW: Add Cetus support.   Thanx to Ron Parker and Kjeld Jensen.
+NEW: Add gpspilot support.
 NEW: Windows support.  You must download and install the expat dll if you
        do not already have it.   Get it from
        http://sourceforge.net/projects/mingwrep/
+
+FIXED: Bad math in gpsutil.
index 207ba839c843c2720af22f905688c4093d605eb4..fdb0587c591f8de19f740389a86a7580444dc1d3 100644 (file)
@@ -3,7 +3,8 @@ CFLAGS=-g -Icoldsync
 FMTS=magproto.o gpx.o geo.o gpsman.o mapsend.o mapsource.o \
        gpsutil.o tiger.o pcx.o csv.o cetus.o gpspilot.o magnav.o
 
-OBJS=main.o queue.o route.o waypt.o util.o vecs.o coldsync/util.o coldsync/pdb.o $(FMTS)
+OBJS=main.o queue.o route.o waypt.o util.o vecs.o mkshort.o \
+       coldsync/util.o coldsync/pdb.o $(FMTS)
 
 all: gpsbabel
 
index 2209882954cd783122865cc99258f85d7aa30fc9..9ec0d593f1ced97ce12fd3720192ac82a2eb6591 100644 (file)
@@ -33,7 +33,14 @@ THE FORMATS
 
     MAGELLAN
 
-       Waypoint upload and download works reliably.
+       Waypoint serial upload and download works reliably to the 315, 330, 
+       Meridian, and SportTrak family.  I expect it to work on any modern
+       Magellan unit.
+
+       As of 08/30/02, gpsbabel can also read and write the files that
+       can be stuck on the flash memory parts 
+
+BLAH BLAH BLAH
 
        As of this writing, there is still a lot of "scribbling" in the 
        source for functionality that isn't hooked up to the rest of the
@@ -78,6 +85,19 @@ THE FORMATS
        yet, a module that implements it.   I spent time trying to reverse-
        engineer a couple of *.mps files then I remembered that I don't own
        a Garmin and wasn't that inspired.
+
+    CETUS
+
+       Cetus GPS (http://www.cetusgps.dk/) is a program for Palm/OS.  
+       Working with Ron Parker and Kjeld Jensen, we can now read and write
+       files for that program.   It hasn't been exhaustively tested, but 
+       has seemed fine on every input and output we've tried.
+
+    GPSPILOT
+
+       The file format for GPSPILOT (http://www.gpspilot.com) was provided
+       by Ron Parker.  GPSbabel can currently read gpspilot files, but not
+       write them.
        
 
 COMMON USAGE
index fe57a43533b37c6cb597aebeb27303b20223cfb7..bdc7e0d44d64e46185bb47cb1e667e5252de005b 100644 (file)
  * data in this file.
  */
 
+typedef struct {
+       int synthesize_shortnames;
+} global_options;
+
+extern global_options global_opts;
+
 /*
  * A coordinate in space.
  */
@@ -86,6 +92,9 @@ void route_add (waypoint *);
 void waypt_disp_all(waypt_cb);
 unsigned int waypt_count(void);
 void fprintdms(FILE *, coord *, int);
+char *mkshort (const char *);
+void setshort_length(int n);
+void setshort_badchars(const char *);
 
 typedef struct ff_vecs {
        ff_init rd_init;
index 18a6886654005422c88f66e7e505efee58a5b0e5..1b046a128ed563e6745745b6527d00b036bde4c0 100644 (file)
@@ -89,7 +89,8 @@ gpsutil_disp(waypoint *wpt)
        lat = wpt->position.latitude.degrees * 100.0;
 
        fprintf(file_out, "%-8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n",
-               wpt->shortname,
+                global_opts.synthesize_shortnames ?
+                        mkshort(wpt->description) : wpt->shortname,
                fabs(lat),
                lat < 0.0 ? 'S' : 'N',
                fabs(lon),
index dc226adfaa24fe36b680016838feb59231263453..0b5a64a5492c1d1d5081d026a46feec596f007f4 100644 (file)
@@ -737,7 +737,8 @@ mag_waypt_pr(waypoint *waypointp)
                lat, ilon < 0 ? 'N' : 'S',
                lon, ilat < 0 ? 'E' : 'W',
                waypointp->position.altitude.altitude_meters,
-               waypointp->shortname,
+                global_opts.synthesize_shortnames ?
+                        mkshort(waypointp->description) : waypointp->shortname,
                waypointp->description ? waypointp->description : "",
                icon_token);
        mag_writemsg(obuf);
index 4288e713d40b14ea710680b3a12581162001beaf..4ec9cc2d7fb24559d0fde4476683a6def34d8cf2 100644 (file)
 
 #include "defs.h"
 
+global_options global_opts;
+
 void
 usage(const char *pname)
 {
-       printf("Usage: %s -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
+       printf("Usage: %s [-s] -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
        printf("Supported file types:\n");
        disp_vecs();
 }
@@ -60,17 +62,19 @@ main(int argc, char *argv[])
 
                c = argv[argn][1];
                optarg = argv[argn+1];
-               argn++;
 
                switch (c) {
                        case 'i': 
                                ivecs = find_vec(optarg);
+                               argn++;
                                break;
                        case 'o':
                                ovecs = find_vec(optarg);
+                               argn++;
                                break;
                        case 'f':
                                fname = optarg;
+                               argn++;
                                if (ivecs == NULL) {
                                        fatal ("No valid input type specified");
                                }
@@ -79,11 +83,15 @@ main(int argc, char *argv[])
                                break;
                        case 'F':
                                ofname = optarg;
+                               argn++;
                                if (ovecs) {
                                        ovecs->wr_init(ofname);
                                        ovecs->write();
                                }
                                break;
+                       case 's':
+                               global_opts.synthesize_shortnames = 1;
+                               break;
                        case 'h':
                        case '?':
                                usage(argv[0]);
index 5bc6aa8f00535550e17966dc2c4ebb74a38fa909..932390c0a925845b1c7fbc613ea282811ade0f4a 100644 (file)
@@ -1,14 +1,20 @@
 #include <string.h>
 
-const char badchars[] = "\"$.,'!-";
-const char vowels[] = "aeiouAEIOU";
+static const char vowels[] = "aeiouAEIOU";
 
-#define TGT_LEN 8
+#define DEFAULT_TARGET_LEN 8
+static int target_len = DEFAULT_TARGET_LEN;
+
+#define DEFAULT_BADCHARS "\"$.,'!-"
+static const char *badchars = DEFAULT_BADCHARS;
+
+static int mustupper = 0;
 
 /*
  * This is the stuff that makes me ashamed to be a C programmer...
  */
 
+static 
 char *
 delete_last_vowel(int start, char *istring, int *replaced)
 {
@@ -33,6 +39,41 @@ delete_last_vowel(int start, char *istring, int *replaced)
 
 }
 
+/*
+ * Externally callable function to set the max length of the
+ * strings returned by mkshort().  0 resets to default.
+ */
+void
+setshort_length(int l)
+{
+       if (l == 0) {
+               target_len = DEFAULT_TARGET_LEN;
+       } else {
+               target_len = l;
+       }
+}
+
+/*
+ * Externally callable function to set the string of characters
+ * that must never appear in a string returned by mkshort.  NULL
+ * resets to default.
+ */
+void
+setshort_badchars(const char *s)
+{
+       if (s == NULL) {
+               badchars = DEFAULT_BADCHARS;
+       } else {
+               badchars = strdup(s);
+       }
+}
+
+void
+setshort_mustupper(int i)
+{
+       mustupper = i;
+}
+
 char *
 mkshort(char *istring)
 {
@@ -88,6 +129,9 @@ mkshort(char *istring)
        cp = ostring;
        for (i=0;i<l;i++) {
                if (!isspace(tstring[i])) {
+                       if (mustupper) {
+                               tstring[i] = toupper(tstring[i]);
+                       }
                        *cp++ = tstring[i];
                }
        }
@@ -132,7 +176,7 @@ mkshort(char *istring)
         * them.  If we run out of string, give up.
         */
        replaced = 1;
-       while (replaced && strlen(ostring) > TGT_LEN) {
+       while (replaced && strlen(ostring) > target_len) {
                ostring = delete_last_vowel(2, ostring, &replaced);
        }
        
@@ -154,13 +198,13 @@ mkshort(char *istring)
         * Now brutally truncate the resulting string, preserve trailing 
         * numeric data.
         */
-       if ((i = strlen(ostring)) > TGT_LEN) {
-               strcpy(&ostring[TGT_LEN] - strlen(np), np);
+       if ((i = strlen(ostring)) > target_len) {
+               strcpy(&ostring[target_len] - strlen(np), np);
        }
        return ostring;
 }
 
-
+#if 0
 char *foo[] =  {
 "VwthPst# 3700.706N 08627.588W 0000000m View the Past #2              ",
 "PilotRoc 3655.270N 08717.173W 0000000m Pilot Rock by CacheAdvance    ",
@@ -335,3 +379,4 @@ printf("%s\n", delete_last_vowel(0, "ixxx", &r));
 printf("%s\n", delete_last_vowel(0, "aexxx", &r));
        
 }
+#endif
index f65b83ed2a86f9d3469f300c066e276b7746034c..4cffcc017e639330c40675ad8d2517a16e90c3be 100644 (file)
@@ -114,7 +114,8 @@ gpsutil_disp(waypoint *wpt)
        }
 
        fprintf(file_out, "W  %-6.6s %c%08.5f %c%011.5f %s %5d %-40.40s %5e  %s\n",
-               wpt->shortname,
+                global_opts.synthesize_shortnames ?
+                        mkshort(wpt->description) : wpt->shortname,
                lat < 0.0 ? 'S' : 'N',
                fabs(lat),
                lon < 0.0 ? 'W' : 'E',
@@ -140,7 +141,7 @@ fprintf(file_out,
 "U  LAT LON DM\n"
 "\n"
 "H  IDNT   LATITUDE    LONGITUDE    DATE      TIME     ALT   DESCRIPTION                              PROXIMITY     SYMBOL ;waypts\n");
-
+       setshort_length(6);
        waypt_disp_all(gpsutil_disp);
 }
 
index 0e47703c71267c3dcb2b6ff52f12758fb47f609a..71d421ea7ac74c6ffa4ed8c3083176cf36225d61 100644 (file)
@@ -53,7 +53,8 @@ waypt_disp(waypoint *wpt)
        printposn(&wpt->position.latitude,1);
        printposn(&wpt->position.longitude,0);
        printf("%s/%s %f\n", 
-               wpt->shortname, 
+               global_opts.synthesize_shortnames ? 
+                       mkshort(wpt->description) : wpt->shortname, 
                wpt->description, 
                wpt->position.altitude.altitude_meters);
 }
@@ -63,7 +64,8 @@ waypt_disp_all(waypt_cb cb)
 {
        queue *elem, *tmp;
        waypoint *waypointp;
-
+setshort_length(8);
+setshort_mustupper(0);
        QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
                waypointp = (waypoint *) elem;
                (*cb) (waypointp);